home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TANK11.ZIP / SOURCE.ZIP / DRAW.C < prev    next >
C/C++ Source or Header  |  1993-01-16  |  4KB  |  126 lines

  1. /* DRAW.C contains graphics screen routines */
  2.  
  3. #include <stdlib.h>
  4. #include <dos.h>
  5. #include <conio.h>
  6.  
  7. #include "tankdefs.h"
  8. #include "types.h"
  9. #include "extern.h"
  10.  
  11. #define F      25 /* border foreground color */
  12. #define BCOLOR 25 /* color of blockades on screen */
  13. #define TNAME  0x07 /* tank name color */
  14. #define SC   0x0F /* score color */
  15. #define TC   0x0E /* SUPER TANK */
  16.  
  17. void drawit(int x, int y, int c, int r, char *buf)
  18. /* requires: x,y coordinates of upper left corner object
  19.  *              c,r dimensions of object
  20.  *              buf = array of char colors
  21.  * ensures:  object drawn on screen
  22.  */
  23. {  register int r1,c1;
  24.     for(r1=0;r1<r;r1++)
  25.         for(c1=0;c1<c;c1++) *(vbuf+(y+r1)*320+x+c1)=*(buf+r1*c+c1);
  26. }
  27.  
  28. /* DRAWBOX: Draws boxes on the screen
  29.  * requires: vid mode 13
  30.  * ensures:  box drawn with corner coords as given
  31.  */
  32. void drawbox(int xl, int yl, int xr, int yr, char c)
  33. {
  34.     int x,y;
  35.     for(y=yl;y<yr;y++)
  36.       for(x=xl;x<xr;x++) *(vbuf+y*320+x)=c;
  37. }
  38.  
  39.  
  40. void restart()
  41. /*    requires: none
  42.  * ensures:  graphics mode set, screen drawn, varaibles reset as req'd.
  43.  */
  44. {  int x,y,x1,y1,i;
  45.     char temp[20];
  46.     tankRec *t;
  47.  
  48.     mode(0x13);
  49.  
  50.     PutString13( "                                        ",0,0,F,0);
  51.     PutString13( "┌──────────────────────────────────────┐",0,8,F,0);
  52.     PutString13( "│                                      │",0,16,F,0);
  53.     PutString13( "│                                      │",0,24,F,0);
  54.     PutString13( "│                                      │",0,32,F,0);
  55.     PutString13( "│                                      │",0,40,F,0);
  56.     PutString13( "│                                      │",0,48,F,0);
  57.     PutString13( "│                                      │",0,56,F,0);
  58.     PutString13( "│                                      │",0,64,F,0);
  59.     PutString13( "│                                      │",0,72,F,0);
  60.     PutString13( "│                                      │",0,80,F,0);
  61.     PutString13( "│                                      │",0,88,F,0);
  62.     PutString13( "│                                      │",0,96,F,0);
  63.     PutString13( "│                                      │",0,104,F,0);
  64.     PutString13( "│                                      │",0,112,F,0);
  65.     PutString13( "│                                      │",0,120,F,0);
  66.     PutString13( "│                                      │",0,128,F,0);
  67.     PutString13( "│                                      │",0,136,F,0);
  68.     PutString13( "│                                      │",0,144,F,0);
  69.     PutString13( "│                                      │",0,152,F,0);
  70.     PutString13( "│                                      │",0,160,F,0);
  71.     PutString13( "│                                      │",0,168,F,0);
  72.     PutString13( "│                                      │",0,176,F,0);
  73.     PutString13( "└──────────────────────────────────────┘",0,184,F,0);
  74.  
  75.     if (NumTanks==3) {
  76.         PutString13( "Yellow:", 120, 0, TNAME, 0);
  77.        sprintf(temp,"%-2d",tank[2].score);
  78.        PutString13(temp, 176, 0 ,SC,0);
  79.     } else PutString13( "SUPER TANK",112,0,TC,0);
  80.     PutString13( "Red:",48,0,TNAME,0);
  81.     PutString13( "Blue:",220,0,TNAME,0);
  82.     sprintf(temp,"%-2d",tank[1].score);
  83.     PutString13(temp,80,0,SC,0);
  84.     sprintf(temp,"%-2d",tank[0].score);
  85.     PutString13(temp,259,0,SC,0);
  86.  
  87.     newscreen=0;
  88.  
  89.       /* reset the field array */
  90.       for(x=0;x<FIELDX;x++)
  91.         for(y=0;y<FIELDY;y++) field[x][y]=255;
  92.  
  93.       /* draw some random blocks */
  94.     for (i=0;i<23;i++) {
  95.         x = 30 + 20 * random(13);
  96.         y = 30 + 20 * random(7);
  97.         drawbox(x, y, x+20, y+20, BCOLOR);
  98.     }
  99.  
  100.     /* draw trees if option selected */
  101.     if (TreesOn)  {
  102.         for (i=0;i<NumTanks;i++) tank[i].treeshit=0;
  103.         for (i=0;i<NUMTREES;i++) {
  104.             x = 30 + 20 * random(13);
  105.             y = 44 + 20 * random(6);
  106.             /* enter each non-zero position in the bitmap into field[][] */
  107.             for (y1=0;y1<TREEYDIM;y1++) {
  108.                 for(x1=0;x1<TREEXDIM;x1++)
  109.                     if ( *(TreeBM+y1* TREEXDIM +x1)!=0) field[(x1+x)][(y1+y)]=i;
  110.             }
  111.             tree[i].x=x;
  112.             tree[i].y=y;
  113.             drawit(x, y, TREEXDIM, TREEYDIM, TreeBM);
  114.         }
  115.      }
  116.  
  117.     /* initialize each tank */
  118.     for (i=0;i<NumTanks;i++) {
  119.         tank[i].speed=tank[1].speed=TankSpeed;
  120.         tank[i].x=TankInitialX[i];
  121.         tank[i].y=TankInitialY[i];
  122.         drawit(tank[i].x, tank[i].y, TXDIM, TYDIM, tank[i].pic[tank[i].dir]);
  123.         shotdata[i].range=0; /* reset all shots */
  124.     }
  125.  
  126. }